<?php
  include ('header.php');
?>
<head>
<title><?php echo $titles['admin_add_user']?></title>
</head>




<?PHP
//$_SESSION['username']='';
if (isset ($_GET['username']) && $_GET['username'])
{
$_POST['username']=$_GET['username'];
}
/*
foreach ($_POST as $key=>$val) {
echo $key ."|". $val . "<br />";}
*/
 if (isset($_POST['add']) && $_POST['add'] ) {
 if($_POST['username'] && $_POST['real_name']  ){
 $sql = "Delete from users where username='".$_POST['username']."'";
 $res = mysql_query($sql, $db);

 $sql = "INSERT INTO users (id,username, access,real_name, cabinet,tel)
 VALUES ('".$_POST['id']."', '".$_POST['username']."','".$_POST['access']."','".$_POST['real_name']."','".$_POST['auditory']."','".$_POST['telefon']."')";
 if(mysql_query($sql, $db))
 {
 echo "<script>alert('".$messages[ok]."')</script>";
 }
 
}else  echo "<script>alert('".$messages[not_all_column]."')</script>";
}

$sql="SELECT * FROM users where username='".$_POST['username']."'";  
$process=mysql_query($sql, $db);
$row = mysql_fetch_array($process);

?>

<body>
<?php
echo "<form name=\"add_item\" action=\"".$_SERVER['PHP_SELF']."?username=".$_POST['username']." \" method=\"post\" width='80%'>";
if (!$_POST['username'])
{
$sql2="SELECT max(id) as maxid FROM users ";  
$process2=mysql_query($sql2, $db);
$row2 = mysql_fetch_array($process2);
$row[id]=$row2[maxid]+1;
}
?>
<table class=ALL_INVENTORY_EDIT>
<tr><td class=ALL_INVENTORY_EDIT>
Id
 </td></td><td class=ALL_INVENTORY_EDIT><input type="text" name="id" size=3  value='<?php echo $row[id]?>'>
</td></tr>

<tr><td class=ALL_INVENTORY_EDIT>

Імя </td></td><td class=ALL_INVENTORY_EDIT><input type="text" name="username" size=10  value='<?php echo $row[username]?>'>
</td></tr>
<tr><td class=ALL_INVENTORY_EDIT>
Полное имя </td><td class=ALL_INVENTORY_EDIT><input type="text" name="real_name" size=17 value='<?php echo $row[real_name]?>'>
</td></tr>
<tr><td width=250 class=ALL_INVENTORY_EDIT>
Доступ </td><td class=ALL_INVENTORY_EDIT>
<SELECT NAME="access">
<?php 
for($i=1;$i<=3;$i++){
$selected=($i==$row[access]) ? ' selected' :'';
echo "<option value='".$i."' ".$selected.">".$u_access[$i]."</option>";
}
?>
</SELECT>
</td></tr>


<tr><td class=ALL_INVENTORY_EDIT>
Аудитория </td><td class=ALL_INVENTORY_EDIT>
<SELECT NAME="auditory">
<?php 
$sql2="SELECT * FROM auditories where auditory_id<>0";  
$process2=mysql_query($sql2, $db);
$i=1;
while ($row2 = mysql_fetch_array($process2, $i)){
$selected=($row2[auditory_id]==$row[auditory]) ? ' selected' :'';
echo "<option value='".$row2[auditory_id]."' ".$selected.">".$row2[auditory_name]."</option>";
}
?>
</SELECT>
</td></tr>

<tr><td class=ALL_INVENTORY_EDIT>
Телефон </td><td class=ALL_INVENTORY_EDIT><input type="text" name="telefon" size=10 value='<?php echo $row[tel]?> '>
</td></tr>


</table>
<table class=ALL_INVENTORY_EDIT>
<tr><td align=center>
<input type="submit" value="<?php echo $texts['save'] ?>" name="add">
<input type="button" value="Новий запис" name="new" onClick="javascript:window.location='admin_edit_user.php';">
</tr></td>
</table>
</form>
</body>

 
</html>
<?php
  include ('footer.php');
?>